<?php
/**
 * Created by PhpStorm.
 * User: fangwei
 * Date: 2019-08-21
 * Time: 11:05
 */

namespace App\Http\Controllers\Admin\Api;


use App\Http\Controllers\Controller;
use App\Http\Repositories\Services\IHouse;
use App\Http\Requests\Admin\HouseInputDTO;
use App\Util\LayUiVo;
use App\Util\ResultsVo;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Lang;

class HouseController extends Controller
{
    protected $houseService;
    public function __construct(IHouse $houseService)
    {
        $this->houseService = $houseService;
    }

    public function store(HouseInputDTO $inputDTO){
        $this->houseService->store($inputDTO);
        return response()->json(new ResultsVo(['message'=>Lang::get('response.success')]));
    }

    public function page(Request $request){
        $search = [];
        if ($request->get('name')) {
            $search['name'] = $request->get('name');
        }
        $data = $this->houseService->lists($search,$request->get('page',1),$request->get('limit','10'));
        return response()->json(new LayUiVo(['data'=>$data,'message'=>Lang::get('response.success')]));
    }

    public function delete($id){
        $this->houseService->delete($id);
        return response()->json(new ResultsVo(['message'=>Lang::get('response.success')]));
    }

    public function update(HouseInputDTO $inputDTO,$id) {
        $this->houseService->update($inputDTO,$id);
        return response()->json(new ResultsVo(['message'=>Lang::get('response.success')]));
    }
}